package rin.android.gamble;
import java.util.ArrayList;

import rin.android.database.ClassPlayer;
import rin.android.database.Database;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.TextView;


public class HeightDollar extends MyApp{
	 LinearLayout content;
	 ArrayList<ClassPlayer> listDollar;
	 @Override
	    protected void onCreate(Bundle savedInstanceState) {
		 super.onCreate(savedInstanceState);
		 setContentView(R.layout.activity_heightscore);
		 content = (LinearLayout) findViewById(R.id.content);
		 Database mDatabase = new Database(this);
	     mDatabase.openDatabase();
	     listDollar = mDatabase.getListPlayer();
	     mDatabase.closeDatabase();
	     int n = 0;
	     if(listDollar.size() >10) n = 10; // neu lon hon 10 thi chi lay 10 nguoi thoi
	     else n = listDollar.size();
	     for (int i = 0; i < n; i++) {
	    	 content.addView(getView(i, listDollar.get(i)));
	     }
	 
	        Button button_yes = (Button) findViewById(R.id.button_yes);
	        button_yes.setOnClickListener(new View.OnClickListener() {
	 
	            @Override
	            public void onClick(View v) {
	                MainActivity.mSound.playClick();
	                HeightDollar.this.finish();
	            }
	        });
	 }
	private View getView(int stt, ClassPlayer mClassPlayer) {
		// TODO Auto-generated method stub
		View v = View.inflate(this, R.layout.item_top10, null);
        TextView txt_stt = (TextView) v.findViewById(R.id.txt_stt);
        TextView txt_name = (TextView) v.findViewById(R.id.txt_name);
        TextView txt_dollar = (TextView) v.findViewById(R.id.txt_dollar);
 
        txt_stt.setText("" + (stt + 1));
        txt_name.setText(mClassPlayer.getName());
        txt_dollar.setText(String.valueOf(mClassPlayer.getDollar()));
        return v;
	}
	 @Override
	 public void onBackPressed() {
	        super.onBackPressed();
	        MainActivity.mSound.playClick();
	        HeightDollar.this.finish();
	 }
}
